class BasecodeController < ApplicationController
#before_filter :login_required, :except=> [ :index, :list]


  def index
    @mastercode  = Commoncode.find_master_codes
    @basecode = Commoncode.search(params[:parentcode])
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @commoncodes }
    end
  end

  def basecode
    if request.post?
      @result = float(params[:arg1].send(params[:opeartor],params[:arg2]))
    end
  end

  def changedata

      @basecode = Commoncode.search(params[:parentcode])

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @basecode }
    end

  end


  # GET /basecode/1
  # GET /basecode/1.xml
  def show
    @basecode = Commoncode.find(params[:id])
    @mastercode = Commoncode.find(:first, :conditions => ["Codelevel = 0 and Code = ?", @basecode.ParentCode ])

  end

  # GET /basecode/new
  # GET /basecode/new.xml
  def new
    @basecode = Commoncode.new
    @mastercode = Commoncode.find(:all, :conditions => ["Codelevel = 0"])
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @basecode }
    end
  end

  # GET /basecode/1/edit
  def edit
    @basecode = Commoncode.find(params[:id])
    @mastercode = Commoncode.find(:all, :conditions => ["Codelevel = 0"])
  end

  # POST /basecode
  # POST /basecode.xml
  def create
    @basecode = Commoncode.new(params[:basecode])
    @mastercode = Commoncode.find(:all, :conditions => ["Codelevel = 0"])
    respond_to do |format|
      if @basecode.save
        flash[:notice] = 'basecode was successfully created.'
        format.html { redirect_to(@basecode) }
        format.xml  { render :xml => @basecode, :status => :created, :location => @basecode }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @basecode.errors, :status => :unprocessable_entity }
      end
    end
  end

   # PUT /basecode/1
  # PUT /basecode/1.xml
  def update
    @basecode = Commoncode.find(params[:id])
    @mastercode = Commoncode.find(:all, :conditions => ["Codelevel = 0"])
    respond_to do |format|
      if @basecode.update_attributes(params[:basecode])
        flash[:notice] = 'Commoncode was successfully updated.'
        format.html { redirect_to(@basecode) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @basecode.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /basecode/1
  # DELETE /basecode/1.xml
  def destroy
    @basecode = Commoncode.find(params[:id])
    @basecode.destroy

    respond_to do |format|
      format.html { redirect_to(:action => "index" ) }
      format.xml  { head :ok }
    end
  end
end
